﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BoneImp {
	public abstract class Timeline {
		public int FrameCount;

		public Timeline(int frameCount) {
			this.FrameCount = frameCount;
		}

		public abstract void apply(SkeletonBase skeleton, float time, float alpha);

		/* @param target After the first and before the last entry. */
		protected static int binarySearch(float[] values, int valuesLength, float target, int step) {
			int low = 0;
			int high = valuesLength / step - 2;
			if (high == 0) return step;
			int current = high >> 1;
			while (true) {
				if (values[(current + 1) * step] <= target)
					low = current + 1;
				else
					high = current;
				if (low == high) return (low + 1) * step;
				current = (low + high) >> 1;
			}
		}

		/*static int linearSearch (float *values, int valuesLength, float target, int step) {
		 int i, last = valuesLength - step;
		 for (i = 0; i <= last; i += step) {
		 if (values[i] <= target) continue;
		 return i;
		 }
		 return -1;
		 }*/

		abstract internal float GetDuration();
	}
}
